package com.example.tuike.service;

import com.example.tuike.entity.Feeds;
import com.example.tuike.mapper.FeedsMapper;
import com.example.tuike.mapper.SubscriptionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/*** @Author supersaiya
 * @Description TODO

 * @Date 2025/2/2 21:18

 * @Version 1.0*/

@Service
public class FeedsService {

    @Autowired
    private FeedsMapper feedsMapper;

    @Autowired
    private SubscriptionMapper subscriptionMapper;

    public List<Feeds> getAllFeeds() {
        return feedsMapper.findAll();
    }

    public Feeds getFeedById(Integer feedId) {
        return feedsMapper.findById(feedId);
    }

    public Feeds createFeed(Feeds feed) {
        feed.setLastUpdated(LocalDateTime.now());
        feedsMapper.insert(feed);
        return feed;
    }

    public Feeds updateFeed(Feeds feed) {
        feed.setLastUpdated(LocalDateTime.now());
        feed.setTitle(feed.getTitle());
        feedsMapper.update(feed);
        return feed;
    }

    public void deleteFeed(Integer feedId) {
        feedsMapper.delete(feedId);
    }

}